﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Domain.Repositories;
using YAPACS.BusinessObjects.Managements.Devices;

namespace YAPACS.RisServer.Controllers;
[Authorize]
public class StationController : AbpControllerBase
{
    private readonly IRepository<Station, Guid> _stationRepository;

    public StationController(IRepository<Station, Guid> stationRepository)
    {
        _stationRepository = stationRepository;
    }

    [AllowAnonymous]
    [HttpGet("/api/station/get-station-info/{stationCode}")]
    public async Task<IActionResult> GetStationInfo(string stationCode)
    {
        try
        {
            var station = await _stationRepository.GetAsync(x => x.Code == stationCode);
            var room = station.Room;
            var department = room.Department;
            return Ok(new
            {
                Success = true,
                Data = new
                {
                    room.Id,
                    room.Name,
                    room.Code,
                    room.Logo,
                    room.Alias,
                    DepartmentId = department.Id,
                    DepartmentName = department.Name,
                    DepartmentCode = department.Code,
                    DepartmentLogo = department.Logo,
                    DepartmentAlias = department.Alias,
                    DepartmentAlias2 = department.Alias2,
                    DepartmentAlias3 = department.Alias3,
                    InstitutionName = department.Institution.Name,
                    InstitutionLogo = department.Institution.Logo,
                    InstitutionAlisa = department.Institution.Alias,
                    InstitutionAlisa2 = department.Institution.Alias2,
                }
            });
        }
        catch (Exception ex)
        {
            return Ok(new
            {
                Success = false,
                Error = ex.Message
            });
        }
    }
}
